<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="javax.jdo.Query"%>
<%@page import="de.upb.messerschmidt.set.entity.Event"%>
<%@page import="de.upb.messerschmidt.set.entity.Room"%>
<%@page import="de.upb.messerschmidt.set.entity.Person"%>
<%@page import="de.upb.messerschmidt.set.jdo.PMF"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Event Registration</title>
</head>

<body>
	<h1>Event Registration</h1>
	<p>Please enter the event information and submit by pressing the
		button</p>
	<form action="post/attend/event" method="post">
		<!-- Locations mit JSP abrufen -->
		<table>
			<tr>
				<td>Event:</td>
				<td><select name="event" size="1">
						<%
							PersistenceManager pm = PMF.get().getPersistenceManager();
							Query query = pm.newQuery(Event.class);
							query.setOrdering("title desc");
							try {
								@SuppressWarnings("unchecked")
								List<Event> events = (List<Event>) query.execute();
								if (!events.isEmpty()) {
									for (Event e : events) {
						%>
						<option>
							<%=e.getTitle() + " at " + e.getLocation()%>
						</option>
						<%
							}
								}
							}

							catch (Exception e) {
								e.printStackTrace();
							}
						%>
				</select>
				</td>
			</tr>
			<tr>
				<td>Person:</td>
				<td><select name="person" size="1">
						<%
							Query personQuery = pm.newQuery(Person.class);
							personQuery.setOrdering("name desc");
							try {
								@SuppressWarnings("unchecked")
								List<Person> persons = (List<Person>) personQuery.execute();
								if (!persons.isEmpty()) {
									for (Person p : persons) {
						%>
						<option>
							<%=p.getName() + ", " + p.getPrename()%>
						</option>
						<%
							}
								}
							}

							catch (Exception e) {
								e.printStackTrace();
							}
						%>
				</select>
				</td>
			</tr>
			<tr>
				<td>Status:</td>
				<td><select name="status" size="1">
						<option>attending</option>
						<option>maybe attending</option>
						<option>not attending</option>
				</select>
				</td>
			</tr>
			<tr>
				<td><input type="submit" value="Submit" />
				</td>
				<td><input type="reset" value="Reset">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
